// Demonstrates current generic support in nrc.
// 1. Generic free functions: can be defined, monomorphized and invoked with explicit type arguments.
// 2. Generic structs: can be declared, instantiated with concrete type arguments, and used like any other type.

type Pair<T> struct {
    value T
}

func identity<T>(value T) T {
    return value
}

func check_generic_functions() {
    var i int = identity<int>(42)
    assert_eq(i, 42, "identity<int> should return the same int")

    var s String = identity<String>("generic")
    assert_eq(s.len(), 7, "identity<String> result should keep the string contents")

    // Compose generic helpers
    var chained int = identity<int>(identity<int>(7))
    assert_eq(chained, 7, "chained identity<int> should still be 7")
}

func check_generic_structs() {
    var pair_int Pair<int> = Pair<int>{ value: 99 }
    assert_eq(pair_int.value, 99, "Pair<int> should keep the int payload")

    var pair_string Pair<String> = Pair<String>{ value: "nrc" }
    var stored_string String = pair_string.value
    var string_len int = stored_string.len()
    assert_eq(string_len, 3, "Pair<String> should store the string payload")

    println("Pair<int> =", pair_int.value, ", Pair<String> =", pair_string.value)
}

func test_generic_demo() {
    println("=== Generic feature demo ===")
    check_generic_functions()
    check_generic_structs()
    println("All generic examples passed")
}
